package com.xcx.robot.spring.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Author: 邢晨旭
 * @Date: 2021/6/30 10:05
 * @Description:
 */
@Component
@Aspect
@Slf4j
public class ExceptionCatchHandler {

    @Around("@annotation(com.xcx.robot.annotation.ExceptionCatch) || @within(com.xcx.robot.annotation.ExceptionCatch)")
    public Object around(ProceedingJoinPoint joinPoint) {
        Object proceedObj = null;
        try {
            proceedObj =  joinPoint.proceed();
        }catch (Throwable throwable){
            log.error("{}执行方法{}报错->{}",joinPoint.getTarget().getClass().getName(),joinPoint.getSignature().getName(),throwable);
        }
        return proceedObj;
    }

}
